package com.example.peanutsubway.web;

import com.alibaba.fastjson.JSONObject;
import com.example.peanutsubway.annotation.ResponseTypeAnnotation;
import com.example.peanutsubway.dao.impl.MenuInfoDaoImpl;
import com.example.peanutsubway.entity.Menu;
import com.example.peanutsubway.service.MenuInfoService;
import com.example.peanutsubway.service.impl.MenuInfoServiceImpl;
import com.example.peanutsubway.util.PageInfo;

import javax.servlet.annotation.WebServlet;

/**
 * @Author：zzt
 * @Version：1.0
 * @Date：2021/10/16-16:29
 * @Since:jdk1.8
 * @Description:
 */
@WebServlet("/menu.do")
public class MenuInfoServlet extends BaseServlet<Menu> {
    private MenuInfoService menuInfoService = new MenuInfoServiceImpl();
    @ResponseTypeAnnotation
    public String showMenu(Menu menu) {
        String nowPage = request.getParameter("page");
        String pageNum = request.getParameter("pageSize");
        PageInfo allMenu = menuInfoService.findAllMenu(menu, nowPage, pageNum);
        return JSONObject.toJSONString(allMenu);
    }

    @ResponseTypeAnnotation
    public String showMenuType(){
        return JSONObject.toJSONString(menuInfoService.findAllMenuType());
    }

    @ResponseTypeAnnotation
    public String updateMenu(Menu menu){
        return JSONObject.toJSONString(menuInfoService.updateMenu(menu));
    }

    @ResponseTypeAnnotation
    public String addMenu(Menu menu){
        return JSONObject.toJSONString(menuInfoService.addMenu(menu));
    }

    @ResponseTypeAnnotation
    public String deleteMenu(){
        String menuId = request.getParameter("menuId");
        return JSONObject.toJSONString(menuInfoService.deleteMenu(Integer.parseInt(menuId)));
    }
}
